package com.example.actearly_revised;

import android.app.Activity;
import android.app.DialogFragment;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;

public class Registration {
	public SQLogic entry;

	Button datePick;
	Button createAccount;
	DialogFragment newFragment;
	Activity actOfCall;
	
	public Activity getActOfCall() {
		return actOfCall;
	}

	public void setActOfCall(Activity actOfCall) {
		this.actOfCall = actOfCall;
	}

	public long update(boolean Add, int profile) { // true for add, false for
													// update
	/*
	 * @SuppressLint("NewApi") public void onCreate(Bundle savedInstanceState) {
	 * newFragment = new DatePickerFragment();
	 * super.onCreate(savedInstanceState);
	 * setContentView(R.layout.activity_date_pick);
	 * 
	 * p_intent = getIntent(); profile = p_intent.getIntExtra("profile_number",
	 * 1);
	 * 
	 * final Calendar c = Calendar.getInstance();
	 * 
	 * // datePick = (Button) findViewById(R.id.datePick);
	 * 
	 * Log.d("stuff", "stuff");
	 * 
	 * // datePick.setOnClickListener(new View.OnClickListener() {
	 * 
	 * //@SuppressLint("NewApi") //@TargetApi(11) //public void onClick(View v)
	 * {
	 * 
	 * newFragment.show(getFragmentManager(), "datePicker");
	 * 
	 * //} //});
	 */
		// createAccount = (Button) findViewById(R.id.Submit);
		// createAccount.setOnClickListener(new View.OnClickListener() {
		// public void onClick(View v) {
		// String temp = ((DatePickerFragment) newFragment).getDate();
		long child = 0;
		
		System.out.println("This is check 1");
		Log.d("usermanger", "try ");
		try {
			entry = new SQLogic(actOfCall);
			entry.open();
			Log.d("usermanger", "open");

			if (!Add) {
				child = entry.UpdateUserEntry(LoginVerify.getChildNameS(),
						LoginVerify.getParentNameS(),
						LoginVerify.getDateOfBirthS(),
						LoginVerify.getDoctorNameS(), LoginVerify.getEmailS(),
						LoginVerify.getGenderS(), LoginVerify.getDoctorsEmailS(), profile); 
										
				System.out.println(entry.getUserData(profile));
				entry.close();
				return child;
			} 
			else {
				child = entry.CreateUserEntry(LoginVerify.getChildNameS(),
						LoginVerify.getParentNameS(),
						LoginVerify.getDateOfBirthS(),
						LoginVerify.getDoctorNameS(), LoginVerify.getEmailS(),
						LoginVerify.getGenderS(), LoginVerify.getDoctorsEmailS());
				entry.close();
				return child;
			}
			// finish();

			// Intent intent = new
			// Intent("com.example.actearly_revised.OptinScreen");
			// intent.putExtra("profile_number", profile);
			// startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return child;
	}
		//});
	//}
}


